package com.sxj.springsourcecode.springframework.factory.support.strategy;

import java.lang.reflect.Constructor;

/**
 * @ProjectName: spring-source-code
 * @Package: com.sxj.springsourcecode.springframework.factory.support.strategy
 * @ClassName: JdkInstantiationStrategy
 * @Author: sxj
 * @Description:
 * @Date: 2024/2/21 13:55
 * @Version: 1.0.0
 */
public class JdkInstantiationStrategy implements InstantiationStrategy{
    @Override
    public Object instantBean(Class clz, Constructor ctr, Object[] args) throws Exception{
        Object bean;
        if (args == null){
            bean = clz.getDeclaredConstructor().newInstance();
        }else {
            Constructor constructor = clz.getDeclaredConstructor(ctr.getParameterTypes());
            bean = constructor.newInstance(args);
        }
        return bean;
    }
}
